package cn.sunjiachao.framework.web.core;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 核心调度过滤器
 * 
 * @author jiachao.sun
 * 
 */
public class DispatcherFilter implements Filter {

	private static Log LOGGER = LogFactory.getLog(DispatcherFilter.class);

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		String configClazz = filterConfig.getInitParameter("configClass");// 获取web.xml中的参数
		LOGGER.debug("config name: " + configClazz);
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
			ServletException {
		HttpServletRequest hreq = (HttpServletRequest) request;
		String servletPath = hreq.getServletPath();// servletPath可以获取从应用路径开始的url
		String contextPath = hreq.getContextPath();// contextPath为应用路径
		LOGGER.debug("servletPath: " + servletPath + " contextPath: " + contextPath);
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {

	}

}
